<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>转工看板</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <el-row class="header">
      <el-col :span="6"><img src="../images/aeec_logo.png" height="60" alt="黎阳LOGO" /></el-col>
      <el-col :span="12" class="header-title">{{title}}</el-col>
      <el-col :span="6" class="currentTime">{{currentTime}}</el-col>
    </el-row>

    <div style="padding:10px;">
      <el-form :inline="true" :model="queryInfo" :label-position="'left'">
        <el-form-item label="承制分厂:">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择" filterable>
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="转工状态">
          <el-select v-model="queryInfo.status" placeholder="请选择" clearable filterable style="width:120px;">
            <el-option :key="'已转出'" :label="'已转出'" :value="'已转出'"></el-option>
            <el-option :key="'已接收'" :label="'已接收'" :value="'已接收'"></el-option>
            <el-option :key="'已完成'" :label="'已完成'" :value="'已完成'"></el-option>
            <el-option :key="'已转回'" :label="'已转回'" :value="'已转回'"></el-option>
            <el-option :key="'已拒收'" :label="'已拒收'" :value="'已拒收'"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item style="height:40px;">
          <el-button type="primary" @click="handleBtnSearch" icon="el-icon-search" size="small">查询</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="40"></el-table-column>
        <el-table-column label="零件图号" prop="productname" width="180" show-overflow-tooltip></el-table-column>
        <el-table-column label="批次号" prop="togetherflag" show-overflow-tooltip></el-table-column>
        <el-table-column label="转出工序" prop="specname" width="180" show-overflow-tooltip></el-table-column>
        <el-table-column label="数量" prop="qty" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column label="接收人" prop="reciver" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="转出分厂" prop="factoryname" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column label="转出时间" prop="submitdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="要求完成时间" prop="plandate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="预计完成时间" prop="estimatedcompletedate" width="100" :formatter="splitDate">
        </el-table-column>
        <el-table-column label="接收时间" prop="toacceptdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="完成时间" prop="completedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="转入时间" prop="returndate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="超期天数" prop="delaydays" width="90" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="scope.row.delaydays <= 0">0</span>
            <span v-else style="color:red;font-weight: bold;">{{scope.row.delaydays}} 天</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" prop="status" width="80" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status === '已拒收'" type="danger">{{scope.row.status}}</el-tag>
            <el-tag v-else-if="scope.row.status === '已转回'" type="success">{{scope.row.status}}</el-tag>
            <el-tag v-else-if="scope.row.status === '已完成'" type="success">{{scope.row.status}}</el-tag>
            <el-tag v-else-if="scope.row.status === '已接收'">{{scope.row.status}}</el-tag>
            <el-tag v-else-if="scope.row.status === '已转出'" type="info">{{scope.row.status}}</el-tag>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
        :page-sizes="[14,50,100]" :page-size="pageSize" layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>
  <script type="module">
    import { getParams } from '../Scripts/hooks/useCommonMethod.js';
    import { getUserInfo, getFactoryListByCode } from '../Scripts/hooks/fetchAPI.js';
    import { splitDate } from '../Scripts/hooks/format.js'
    const app = new Vue({
      el: '#app',
      data: {
        splitDate,
        currentTime: '',// 当前时间
        title: '',// 看板标题
        queryInfo: {
          factoryid: '', //主制分厂
          factoryname: '', //分厂
          status: '' // 处理状态
        },
        currentPage: 1,//当前页
        pageSize: 14, //每页显示条数
        total: 0,// 总条数 
        loading: false,
        loadingText: '拼命加载中',
        dataList: [],
        factoryList: [],
        userInfo: {}
      },
      methods: {
        //查询数据
        async getData(currentpage) {
          this.loading = true;
          this.loadingText = '数据查询中...';
          const { data: { data, meta, total } } = await axios({
            method: 'post',
            url: '../handler/board/ContainerShipRecordDashBoardRB.ashx?action=getData',
            data: {
              action: 'getData',
              ...this.queryInfo,
              currentPage: this.currentPage,
              pageSize: this.pageSize
            }
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.dataList = data;
          this.total = total;
        },
        //监听 currentpage 改变
        handleCurrentChange(newPage) {
          this.currentPage = newPage;
          this.getData();
        },
        //监听 pagezie 改变
        handleSizeChange(newSize) {
          this.pageSize = newSize;
          this.getData();
        },
        handleBtnSearch() {
          this.currentPage = 1
          this.getData()
        }
      },
      async mounted() {
        let incrementNumber = () => {
          setTimeout(incrementNumber, 500);
          this.currentTime = dayjs().format('YYYY年MM月DD日  HH:mm:ss');
        }
        setTimeout(incrementNumber, 500);
        this.userInfo = await getUserInfo({ employeeid: getParams("uid") });
        this.factoryList = await getFactoryListByCode({ factoryCode: '305|602' });//查询 热表|无损
        if (this.userInfo.factoryid && this.factoryList.some(item => item.factoryid === this.userInfo.factoryid)) {
          const { factoryid, factoryname } = this.userInfo;
          this.queryInfo.factoryid = factoryid;
          this.queryInfo.factoryname = factoryname;
        } else {
          this.queryInfo.factoryid = this.factoryList[0].factoryid;
          this.queryInfo.factoryname = this.factoryList[0].factoryname;
        }
        this.title = `${this.queryInfo.factoryname}转工看板`;
        document.title = this.title;
        this.getData();
      },
      watch: {
        queryInfo: {
          handler() {
            this.currentPage = 1;
            this.queryInfo.factoryname = this.factoryList.filter(item => item.factoryid === this.queryInfo.factoryid)[0].factoryname
            this.title = `${this.queryInfo.factoryname}转工看板`
            document.title = this.title
          },
          deep: true
        }
      }
    })
  </script>
</body>

</html>